from socket import socket
from rpc_protocal import RpcProtocal
from time import sleep

IP_SERVER = "127.0.0.1"
PORT_SERVER = 8888
BUF_SIZE = 1024

class RpcClient:
    def __init__(self):
        self.protocal = RpcProtocal()

    def connect(self):
        sock = socket()
        sock.connect((IP_SERVER, PORT_SERVER))
        dict_rpc = {"method": "rpc_add", "params": "22, 51"}
        b_rpc = self.protocal.dump(dict_rpc)

        sock.send(b_rpc)
        print(b_rpc)
        # reply = sock.recv(BUF_SIZE)
        # print(reply)
        sleep(5)

        sock.close()
        print("Well done, ready to close....")


if __name__ == "__main__":
    rpc = RpcClient()
    rpc.connect()